var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
define(["require", "exports", "maishu-chitu-service", "common/static/index"], function (require, exports, maishu_chitu_service_1, index_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    class WeiXinService extends index_1.Service {
        url(path) {
            return index_1.stationPath(path);
        }
        //======================================================
        // Setting
        getSetting() {
            let url = this.url('setting/item');
            return this.get(url);
        }
        saveSetting(setting) {
            let url = this.url('setting/set');
            return this.putByJson(url, { item: setting });
        }
        //======================================================
        //======================================================
        // User
        userList(args) {
            return __awaiter(this, void 0, void 0, function* () {
                let url = this.url("user/list");
                let r = yield this.getByJson(url, { args });
                return r;
            });
        }
        //======================================================
        getMessageTemplateTypes() {
            let url = this.url('WeiXin/GetMessageTemplateTypes');
            return this.get(url);
        }
        openId(code) {
            let url = this.url('WeiXin/GetOpenId');
            return this.get(url, { code });
        }
        /**
         * 通过 OpenId 登录
         * @param code 用于获取 OpenId 的 code
         *
         */
        login(code) {
            let url = this.url('Member/Login');
            return this.postByJson(url, { code }).then(result => {
                //token 为空表示 openid 没有绑定
                if (result.token != null) {
                    WeiXinService.token.value = result.token;
                }
                return result;
            });
        }
        bind(code) {
            let url = this.url('Member/Bind');
            return this.put(url, { code });
        }
        unbind(code) {
            let url = this.url('Member/Unbind');
            return this.put(url, { code });
        }
    }
    exports.WeiXinService = WeiXinService;
    WeiXinService.token = new maishu_chitu_service_1.ValueStore();
    exports.default = new WeiXinService();
});
